#include "sendtextedit.h"
#include <QMimeData>

sendTextEdit::sendTextEdit(QWidget *parent):QTextEdit(parent)
{
  // tip = new QToolTip;
   isHex = false;
}

/*此函数拦截通过粘贴，拖拽的内容*/
void    sendTextEdit::insertFromMimeData(const QMimeData *source)
{
    if(source->hasText() && isHex)
    {
        QByteArray hexStr = source->text().toLocal8Bit();

        foreach (quint8 byte, hexStr) {
            bool isHexByte = false;
            if(byte>='0' && byte <='9')
                isHexByte = true;
            else if(byte>='a' && byte <='f')
                 isHexByte = true;
            else if(byte>='A' && byte <='F')
                isHexByte = true;
            else if(byte=='\r' || byte <='\n'|| byte <=' ')
                 isHexByte = true;
            else
            {
                QRect rect=cursorRect();

                QToolTip::showText(this->mapToGlobal(QPoint(0,0))+ rect.topLeft(),\
                                   "粘贴内容中存在非16进制字符!",NULL,QRect(),2000);
                return ;
            }
            isHexByte =isHexByte;//消灭警告
        }


    }

     QTextEdit::insertFromMimeData(source);
}
